// pages/userSaid/index.js
var common_Js = require("../../../component/common.js")
import Toast from '../../../component/vant/toast/toast';
var app = getApp(), fetchApi = require("../../../utils/httpPost.js")
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgurl: app.getImgUrl(),
    isiphonex: app.globalData.isiphonex,
    isxiaomi: app.globalData.isxiaomi,
    isCollect: false,
    loading: false,
    netWork: false,
    isLoading: true,
    hasData:false,
    shop: [],
    appraises: [],
    pageIndex:1,
    pageSize:6,
    shop_id:0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.data.shop_id = parseInt(options.id)
    this.onHttpInit()
  },

  /**
   * 获取页面数据的 http请求
   */
  onHttpInit: function (shop_id) {
    var that = this
    fetchApi.httpPost('/orderAppraise/list', {
      shop_id: that.data.shop_id,
      pageIndex: that.data.pageIndex,
      pageSize:that.data.pageSize
    }, function (res) {
      if (res.data.code == 0) {
        console.log("评论列表信息返回数据", res.data.data)
        if(res.data.totalcount > 0){
          that.data.pageIndex = that.data.pageIndex + 1
          var saids = res.data.data;
          if(saids.length > 0){
            for (var index in saids) {
              that.data.appraises.splice(that.data.appraises.length, 0, saids[index]);
            }
            that.setData({
              appraises: that.data.appraises,
              hasData: res.data.totalcount > 0 ?true:false
            });
          }
        }
      }else{
        that.setData({ hasData: false  });
      }
      that.setData({ isLoading: false, loading: true, netWork: true, })
    }, function () {
      that.setData({ isLoading: false, loading: true, netWork: true, hasData: false })
    })
  },
  /**
   * 页面相关事件处理函数--监听用户下拉动作  下拉刷新
   */
  onPullDownRefresh: function () {
    this.data.pageIndex = 1
    this.setData({
      loading: false,
      netWork: false,
      isLoading: true,
    })
    this.onHttpInit()
  },
  preImg:function(t){
    console.log("preSunImg", t)
    var a = t.currentTarget.dataset.imageindex, e = t.currentTarget.dataset.imgdata || [];
    var c = [];
    for (var index in e) {
      c.push(e[index].imgUrl)
    }
    common_Js.preImg(a, c)
  },
  /**
     * 获取页面数据的 http请求
     */
  onHttpLoadMore: function () {
    this.onHttpInit()
  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    this.onHttpInit()
  },
})